package com.crayfish.quduo.ui.fragment;

import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.EditText;
import android.widget.ImageView;

import com.crayfish.quduo.R;

/**
 * 输入类型dialog
 * @author crayfish
 *
 */
public class EditFragmentDialog extends DialogFragment implements OnClickListener{

	private static final String CONTENT = "content";
	private String content;
	
	private ImageView iv_false, iv_true;
	private EditText edit_content;
	
	public static EditFragmentDialog newInstance(String content) {
		EditFragmentDialog efDialog = new EditFragmentDialog();
		Bundle bundle = new Bundle();
		bundle.putString(CONTENT, content);
		efDialog.setArguments(bundle);
		return efDialog;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		content = getArguments().getString(CONTENT);
		super.onCreate(savedInstanceState);
	}


	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
		View v = inflater.inflate(R.layout.fragment_dialog_edit, null);
		initView(v);
		edit_content.setText(content);
		iv_false.setOnClickListener(this);
		iv_true.setOnClickListener(this);
		return v;
	}

	private void initView(View v){
		iv_false = (ImageView) v.findViewById(R.id.iv_false);
		iv_true = (ImageView) v.findViewById(R.id.iv_true);
		edit_content = (EditText)v.findViewById(R.id.edit_content);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.iv_false:
			dismiss();
			break;
		case R.id.iv_true:
			dismiss();
			if(listener != null) {
				listener.onEditContent(edit_content.getText().toString());
			}
			break;

		default:
			break;
		}
	}
	
	public EditContentListener listener;
	
	public interface EditContentListener{
		void onEditContent(String Str);
	}
	
	public void setOnEditContentListener(EditContentListener listener){
		this.listener = listener;
	}
}
